/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.ufba.lasid.v1.jitclouds.mda.examples;

import br.ufba.lasid.v1.jitclouds.mda.MDA;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.BasicReplicableList;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.BasicReplicableVirtualMachine;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.IFailoverDeployer;
import br.ufba.lasid.v1.jitclouds.mda.datatypes.ft.IReplicableVirtualMachine;

/**
 *
 * @author aliriosa
 */
public class FailoverSample {
    
   public static void main(String[] args) throws Exception{
        
        MDA.startup();
        MDA.debug("Creating a new Virtual Machine Failover Deployer ...");
        
        IFailoverDeployer deployer = MDA.createVMFailover();
        
        MDA.debug("Virtual Machine Failover Deployer " + deployer.getID() + " ['"+ deployer.getDescription() + "'] has been successfully loaded.");
        
        MDA.debug("Creating a primary virtual machine ... ");
        
        IReplicableVirtualMachine primary = BasicReplicableVirtualMachine.vm2rvm(MDA.createVM());
        
        primary.setID("r0");        
        
        MDA.debug("Primary Virtual Machine " + primary.getID() + " ['"+ primary.getDescription() + "'] has been successfully loaded.");

        MDA.debug("Creating a backup virtual machine ... ");
        
        IReplicableVirtualMachine backup = BasicReplicableVirtualMachine.vm2rvm(MDA.createVM());
        backup.setID("r1");
        MDA.debug("Backup Virtual Machine " + backup.getID() + " ['"+ backup.getDescription() + "'] has been successfully loaded.");
        
        MDA.debug("Creating a initial group view with [r0 = " + primary.getID() + " and r1 = " + backup.getID() + "]");
        BasicReplicableList viewZero = new BasicReplicableList();
        
        
        viewZero.add(primary);
        viewZero.add(backup);
        
        primary.setInitialView(viewZero);
        backup.setInitialView(viewZero);
        
        MDA.debug("Preparing to install failover with {r0 = " + viewZero.get(0) + ", r1 = " + viewZero.get(1) + "}");
        
        deployer.install(primary, backup);
                
    }    
}
